package com.groupseven.happycampus.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.groupseven.happycampus.common.pojo.Referee;
import com.groupseven.happycampus.common.result.LayuiPageVo;
import com.groupseven.happycampus.common.vo.PieVo;
import com.groupseven.happycampus.mapper.RefereeMapper;
import com.groupseven.happycampus.service.RefereeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.Map;

@Service("/refereeService")
public class RefereeServiceImpl implements RefereeService {

    @Autowired
    public RefereeMapper refereeMapper;


    @Override
    public List<Referee> findAll() {
        return refereeMapper.findAll();
    }

    /**
     * 分页查询及模糊查询裁判信息
     * @param params
     * @return
     */
    @Override
    public LayuiPageVo<Referee> selectReferee(Map<String, Object> params) {

        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page, limit);

        List<Referee> refereeList = refereeMapper.selectReferee(params);

        PageInfo<Referee> refereePageInfo = new PageInfo<>(refereeList);

        LayuiPageVo<Referee> refereeLayuiPageVo = new LayuiPageVo<>();
        refereeLayuiPageVo.setCode(0);
        refereeLayuiPageVo.setMsg("分页列表数据");
        refereeLayuiPageVo.setCount((int) refereePageInfo.getTotal());
        refereeLayuiPageVo.setData(refereePageInfo.getList());
        return refereeLayuiPageVo;

    }


    /**
     * 添加裁判信息
     * @param referee
     * @return
     */
    @Override
    public int addReferee(Referee referee) {
        int i = refereeMapper.addReferee(referee);
        return i;
    }


    /**
     * 根据id删除裁判信息
     * @param id
     * @return
     */
    @Override
    public int deleteRefereeById(Integer id) {
        return refereeMapper.deleteRefereeById(id);
    }


    /**
     * 修改裁判信息
     * @param referee
     * @return
     */
    @Override
    public int updateReferee(Referee referee) {
        return refereeMapper.updateReferee(referee);

    }

    /**
     * 裁判级别图
     * @return
     */
    @Override
    public List<PieVo> gradePieData() {
        List<PieVo> pieVos = refereeMapper.gradePieData();
        return pieVos;
    }



}
